//封装请求
import {
  useUserStore
} from '@/store/user.js'
const user = useUserStore()
const baseUrl = 'http://192.168.3.13:3001'
// const baseUrl = 'http://192.168.43.126:3001'
// const baseUrl = 'http://192.168.1.4:3001'
//promise封装
export const requestNet = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseUrl}${options.url}`,
      method: options.method || 'GET',
      data: options.data || {},
      header: options.header || {},
      success: (res) => {
        // console.log(res)
        if (res.data.code == 304) { //验证token是否过期
          uni.showToast({
            title: '登录信息过期,请重新登录',
            icon: 'error'
          })
          setTimeout(() => {
            uni.navigateTo({
              url: '/pages/login/login'
            })
          }, 3000)
          return;
        } else {
          resolve(res)
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}
